/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geergenbein.azw.model.transcription;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 *
 * @author andrew
 */
@Entity
@Table(name = "toned_transcription", 
    uniqueConstraints = @UniqueConstraint(columnNames = 
    {"toned_code_point_id", "transcription_system_id"}))
@NamedQuery(name = "findTonedTranscription", 
    query = "select tt from TonedTranscription tt where " +
    "tt.tonedCodePoint = :tonedCodePoint and " +
    "tt.transcriptionSystem = :transcriptionSystem")
public class TonedTranscription implements Serializable {
    
    private static final long serialVersionUID = 1L;
    private Long id;
    private TonedCodePoint tonedCodePoint;
    private TranscriptionSystem transcriptionSystem;
    private String transcription;

    public TonedTranscription() {
        
    }
    
    public TonedTranscription(TonedCodePoint tcp, TranscriptionSystem ts,
            String transcription) 
    {
        this.tonedCodePoint = tcp;
        this.transcriptionSystem = ts;
        this.transcription = transcription;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().
                append(tonedCodePoint).
                append(transcriptionSystem).
                append(transcription).
                hashCode();
    }

    @Override
    public boolean equals(Object object) {
        
        if (this == object) {
            return true;
        }
        
        if (!(object instanceof TonedTranscription)) {
            return false;
        }
        
        TonedTranscription other = (TonedTranscription) object;
        
        return new EqualsBuilder().
                append(tonedCodePoint, other.getTonedCodePoint()).
                append(transcriptionSystem, other.getTranscriptionSystem()).
                append(transcription, other.getTranscription()).
                isEquals();
        
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                append(tonedCodePoint).
                append(transcriptionSystem).
                append(transcription).
                toString();
    }

    @ManyToOne
    @JoinColumn(name="toned_code_point_id", nullable=false)
    public TonedCodePoint getTonedCodePoint() {
        return tonedCodePoint;
    }

    public void setTonedCodePoint(TonedCodePoint tonedCodePoint) {
        this.tonedCodePoint = tonedCodePoint;
    }

    @Column(length=15, nullable=false)
    public String getTranscription() {
        return transcription;
    }

    public void setTranscription(String transcription) {
        this.transcription = transcription;
    }

    @ManyToOne
    @JoinColumn(name = "transcription_system_id", nullable=false)
    public TranscriptionSystem getTranscriptionSystem() {
        return transcriptionSystem;
    }

    public void setTranscriptionSystem(TranscriptionSystem transcriptionSystem) {
        this.transcriptionSystem = transcriptionSystem;
    }

}
